package com.haisen.dataobject.dto;

import com.alibaba.fastjson.JSON;
import com.haisen.dataobject.entity.Item;
import com.haisen.dataobject.entity.ItemParamValue;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.Id;
import java.util.List;

@Data
public class ItemDto {

    //因为id无法获取值，所以改成uid，更新需要转化下
    private Long id;
    private Long cityId;
    private String cityName;
    private Long countryId;
    private String countryName;
    private String title;
    private String sellPoint;
    private Integer price;
    private Integer num;
    private String barcode;
    private String image;
    private Long catId;
    private String catName;
    private Byte up;
    //以后可以考虑宝这个作为临时接收json数据的字段
    private String paramjson;
    private List<ItemParamValue> itemParamValueList;
    private String itemParamValueStr;


    //dto作为接收对象，json和list相互转换
  public void setParamjson(String paramjson) {
        //没有将字串转化为数组
        setItemParamValueList(JSON.parseArray(paramjson,ItemParamValue.class));
        this.paramjson = paramjson;
    }

    public List<ItemParamValue> getItemParamValueList() {
        return itemParamValueList;
    }

    public void setItemParamValueList(List<ItemParamValue> itemParamValueList) {
        this.paramjson = JSON.toJSONString(itemParamValueList);
         StringBuilder s = new StringBuilder();
        for (ItemParamValue itemParamValuetemp : itemParamValueList) {
             s.append(itemParamValuetemp.getParamName()+":"+itemParamValuetemp.getParamValue()+"," );
        }
        if (s.length() > 0) {
            s.deleteCharAt(s.length() - 1);
            this.itemParamValueStr = s.toString();
        }

        this.itemParamValueList = itemParamValueList;
    }


}
